package com.qikecn.utils;

import java.util.List;
import java.util.Set;

/**
 * 
 * @author IT_Jeff
 * String 操作类
 *
 */

public class Jeff_StringUtils {

	public static boolean isNotNull(String obj){
		if (null != obj && !obj.trim().equals("") && !obj.trim().equals("null")) {
			return true;
		} else {
			return false;
		}
	}
	
	
	
	public static boolean isNotEmpty(Object obj) {
		if (null == obj || "".equals(obj.toString().trim())) {
			return false;
		} else {
			return true;
		}
	}

	public static boolean isNullOrEmpty(Object obj) {
		if (null == obj || "".equals(obj.toString().trim())) {
			return true;
		} else {
			return false;
		}
	}

	public static String removeLastChar(String sourceStr, String removeStr) {
		if (null != sourceStr && null != removeStr && sourceStr.endsWith(removeStr)) {
			sourceStr = sourceStr.substring(0, sourceStr.length() - removeStr.length());
		}
		return sourceStr;
	}

	public static String removeFirstChar(String sourceStr, String removeStr) {
		if (null != sourceStr && null != removeStr && sourceStr.startsWith(removeStr)) {
			sourceStr = sourceStr.replaceFirst(removeStr, "");
		}
		return sourceStr;
	}

	/**
	 * 字符串Set中是否包含字符串 
	 * @param strSet
	 * @param str
	 * @return
	 */
	public static boolean isHasStr(Set<String> strSet, String str) {
		for (String string : strSet) {
			//Jeff_Systemout.systemout(string+"-----"+str);
			if (string.equals(str)) {
				return true;
			}
		}
		return false;
	}
	
	
	/**
	 * 字符串List中是否包含字符串 
	 * @param strSet
	 * @param str
	 * @return
	 */
	public static boolean isHasStrList(List<String> strList, String str) {
		for (String string : strList) {
			if (string.equals(str)) {
				return true;
			}
		}
		return false;
	}
	
	

	/**
	 * 把类似 1,2,3转为 '1','2','3' 
	 * @param str
	 * @return
	 */
	public static String getInStr(String str) {
		if (null == str || "".equals(str.trim()) || str.startsWith("'")) {
			return str;
		} else {
			if (str.startsWith(",")) {
				str = str.substring(1);
			}
			if (str.endsWith(",")) {
				str = str.substring(0, str.length() - 1);
			}
			String str2 = "";
			String[] temp = str.split(",");
			for (String string : temp) {
				str2 += ",'" + string + "'";
			}
			if (str2.startsWith(",")) {
				str2 = str2.substring(1, str2.length());
			}
			return str2;
		}
	}
	
	/**
	 * IT_Jeff
	 * 2015-04-29
	 * 判断字符串中是否包含“.”
	 * @param args
	 */
	public static String isHasStrForPoint(String str){
		if(str.contains(".")){
			return str.substring(0, str.indexOf("."));
		}else{
			return str;
		}
	}
	
	
	/**
	 * 2016-06-08
	 * 截取字符串，截取字符串0到最后一个字符前一位
	 * 
	 */
	public static String subStringOneToLast(String str){
		String result = "";
		result = str.substring(0, str.length()-1);
		
		return result;
	}
	
	public static String subStringOneToLastStr(String str, String chars){
		String result = "";
		result = str.substring(0, str.lastIndexOf(chars));
		
		return result;
	}
	
	public static String subStringStrToLastStr(String str, String chars){
		String result = "";
		result = str.substring(str.lastIndexOf(chars)+1, str.length());
		
		return result;
	}
	
	public static String subStrByyond(String str){
		String result = "";
		if(str.length() < 12){
			result = str;
		}else{
			result = str.substring(0, 12)+"...";
		}
		return result;
	}
	public static String subStrByyondForTen(String str){
		String result = "";
		if(str.length() < 10){
			result = str;
		}else{
			result = str.substring(0, 10)+"...";
		}
		return result;
	}
	
	public static String subStrByyondForNine(String str){
		String result = "";
		if(str.length() < 9){
			result = str;
		}else{
			result = str.substring(0, 9)+"...";
		}
		return result;
	}
	
	
	public static void main(String[] args) {
		String aa = ",1,2,3,4,";
		System.out.println(removeLastChar(aa, ","));
		System.out.println(removeFirstChar(aa, ","));
		System.out.println(getInStr("1,2,,3,"));
		System.out.println(getInStr("'1','2','3'"));
		
		System.out.println(subStringStrToLastStr("/goodsfirst_add", "_"));
		
		String ss = "创建下拉刷新2342dsafdsf";
		
		System.out.println(subStrByyond(ss)+"----");
		
		
	}
}
